﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Resto.CostControl.Core.Domain.Model;
using Enterprise.Framework.Frame.Architecture;
using Enterprise.Framework.Core.Exceptions;
using Enterprise.Framework.DomainModel.Repositories;

namespace Resto.CostControl.Core.Domain.Query.DishModule
{
    internal class WeekDishDQO : IDomainQueryObject
    {
        public WeekDish GetWeekDish(string id)
        {
            WeekDish material = GetWeekDishOrDefault(id);

            if (material == null)
                throw new BusinessException("指定Id的菜肴不存在");

            return material;
        }

        public WeekDish GetWeekDishOrDefault(string id)
        {
            IEntityRepository<WeekDish> repository = RestoCostDomainSession.CurrentSession.CreateEntityRepository<WeekDish>();
            WeekDish material = repository.Objects.Where(p => p.ID == id).FirstOrDefault();

            return material;
        }

        /// <summary>
        /// 获取某一周的菜单
        /// </summary>
        /// <param name="time">这一周中的任何一天</param>
        /// <returns></returns>
        public WeekDish GetWeekDish(DateTime time)
        {
            IEntityRepository<WeekDish> repository = RestoCostDomainSession.CurrentSession.CreateEntityRepository<WeekDish>();
            WeekDish material = repository.Objects.Where(p =>p.BeginDate <= time && p.EndDate >=time ).FirstOrDefault();

            return material;
        }
    }
}
